# Build recipe for enlightenment (E16).
#
# Copyright (c) 2021 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=e16
version=1.0.22
release=1

# Define a category for the output of the package name
pkgcategory=enlightenment

tarname=${program}-${version}.tar.gz

# Remote source(s)
fetch=https://prdownloads.sourceforge.net/enlightenment/$tarname

description="
The Enlightenment DR16 window manager.

Enlightenment is a window manager for the X Window System that
is designed to be powerful, extensible, configurable and
pretty darned good looking! It is one of the more graphically
intense window managers.

Enlightenment goes beyond managing windows by providing a useful
and appealing graphical shell from which to work. It is open
in design and instead of dictating a policy, allows the user to
define their own policy, down to every last detail.
"

homepage=https://www.enlightenment.org/e16
license=BSD

# Source documentation
docs="AUTHORS COMPLIANCE COPYING ChangeLog TODO"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure CPPFLAGS="$QICPPFLAGS" \
    CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --mandir=$mandir \
     --docdir=$docsdir \
     --enable-dbus \
     --enable-sound=alsa \
     --with-sndldr=audiofile \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1 e16docdir=$docsdir
    make -j${jobs} e16docdir=$docsdir DESTDIR="$destdir" install

    # Compress manual page(s)
    lzip -9 "${destdir}/${mandir}"/*/*.?

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"

    mkdir -p "${destdir}/etc/X11/xinit"
    cat << 'EOF' > "${destdir}/etc/X11/xinit/xinitrc-e16"
#! /bin/sh -

userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
sysresources=/etc/X11/xinit/.Xresources
sysmodmap=/etc/X11/xinit/.Xmodmap

# merge in defaults and keymaps

if [ -f $sysresources ]; then
    xrdb -merge $sysresources
fi

if [ -f $sysmodmap ]; then
    xmodmap $sysmodmap
fi

if [ -f "$userresources" ]; then
    xrdb -merge "$userresources"
fi

if [ -f "$usermodmap" ]; then
    xmodmap "$usermodmap"
fi

# Start the Enlightenment (E16) Window Manager

exec dbus-launch --exit-with-session /usr/bin/e16

EOF

    # To handle .new config file(s)
    touch "${destdir}/etc/X11/xinit/.graft-config"
}

